package com.exam.sacrifice.widget;

import android.os.Handler;
import android.widget.TextView;

public class MultiLineTextAnimator {
    private TextView textView;
    private String[] lines;
    private int currentLine = 0;
    private long lineDelay = 500; // 每行显示间隔

    public MultiLineTextAnimator(TextView textView) {
        this.textView = textView;
    }

    public void animateText(String fullText) {
        this.lines = fullText.split("\n");
        this.currentLine = 0;
        textView.setText("");
        showNextLine();
    }

    public void setLineDelay(long millis) {
        lineDelay = millis;
    }

    private void showNextLine() {
        if (currentLine < lines.length) {
            String currentText = textView.getText().toString();
            String newText = currentText + (currentText.isEmpty() ? "" : "\n") + lines[currentLine];
            textView.setText(newText);
            currentLine++;

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    showNextLine();
                }
            }, lineDelay);
        }
    }
}